//-----------------------------------------------------------------------
// <copyright file="PendingContactCollection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Diagnostics;

    /// <summary>
    /// Represents a collection of pending contacts.
    /// </summary>
    public sealed class PendingContactCollection : Collection
    {
        internal PendingContactCollection(object obj, User user)
            : base(obj, user)
        {
        }

        /// <summary>
        /// Gets the <c>PendingContact</c> at the specific index.
        /// </summary>
        /// <param name="index">The zero-based index of the <c>PendingContact</c> to get.</param>
        /// <returns>The <c>PendingContact</c> at the specified index.</returns>
        public PendingContact this[int index]
        {
            get { return (PendingContact)this.GetItem(index); }
        }

        /// <summary>
        /// Accepts a pending contact and removes it from the collection.
        /// </summary>
        /// <param name="contact">The contact to accept.</param>
        public void Accept(PendingContact contact)
        {
            if (contact == null)
            {
                throw ExceptionHelper.CreateArgumentNullException("contact");
            }

            this.Entity.Invoke("Accept", contact.Entity);
        }

        /// <summary>
        /// Declines a pending contact and removes it from the collection.
        /// </summary>
        /// <param name="contact">The contact to decline.</param>
        public void Decline(PendingContact contact)
        {
            if (contact == null)
            {
                throw ExceptionHelper.CreateArgumentNullException("contact");
            }

            this.Entity.Invoke("Decline", contact.Entity);
        }

        internal override object FindOrCreate(MessengerEntity entity)
        {
            // Always create one since we don't need to worry about tracking references for these.
            return new PendingContact(entity, this.User);
        }
    }
}